package offer;

import java.util.ArrayList;

/**
 * @Author SSK
 * @Date Created in 18:07 2019/8/4
 * @Description 和为S的两个数字
 * @Version 1.0
 */
public class T43 {
    public ArrayList<Integer> FindNumbersWithSum(int [] array, int sum) {
          int l= 0;
          int r = array.length-1;
        ArrayList<Integer> list = new ArrayList<Integer>();
          while (l<r) {
              int ans = array[l] + array[r] ;
              if (ans==sum) {
                  list.add(array[l]);
                  list.add(array[r]);
                  return list;
              } else if (ans>sum) {
                  r--;
              } else {
                  l++;
              }
          }
          return list;
    }
}
